package com.panda.pandawash.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import com.panda.pandawash.R;
import com.panda.pandawash.application.CDApplication;
import com.panda.pandawash.view.SplashView;

public class SplashActivity extends Activity {
    private Handler mHandler = new Handler();

    private Boolean mLoginStatus = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // 透明状态栏
          //  getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                |View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                |View.SYSTEM_UI_FLAG_FULLSCREEN
                |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        }

        SplashView.showSplashView(this, 3, R.drawable.guide_img, new SplashView.OnSplashViewActionListener() {
            @Override
            public void onSplashImageClick(String actionUrl) {
                /*mLoginStatus = CDApplication.getIntance().getLoginStatus();
                if (CDApplication.getIntance().isNewVersion() || !mLoginStatus) {
                    startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                    finish();
                } else {
                    if(CDApplication.getIntance().isNetworkAvailable(SplashActivity.this)) {
                        startActivity(new Intent(SplashActivity.this, PandaWashActivity.class));
                        finish();
                    }else{
                        showMessage(getString(R.string.wifi_not_connect));
                        finish();
                    }
                }*/
            }

            @Override
            public void onSplashViewDismiss(boolean initiativeDismiss) {
                if (CDApplication.getIntance().isNewVersion() || !CDApplication.getIntance().getLoginStatus()) {
                    startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                    finish();
                } else {
                    if(CDApplication.getIntance().isNetworkAvailable(SplashActivity.this)) {
                        CDApplication.getIntance().setLoginStatus(true);
                        startActivity(new Intent(SplashActivity.this, PandaWashActivity.class));
                        showMessage(getString(R.string.login_success));
                        finish();
                    }else{
                        showMessage(getString(R.string.wifi_not_connect));
                        finish();
                    }
                }
            }
        });
    }

    private void showMessage(String string) {
        Toast toast = Toast.makeText(getApplicationContext(), string, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}
